<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
      
<head th:include="head :: htmlhead" th:with="title='协议生成管理'">
</head>
  
<body>
<form class="layui-form" action="" lay-filter="example">
  <textarea class="form-control" id="content" name="content" hidden="true"></textarea>
  <div class="layui-form-item layui-inline" style="margin-top: 10px;">
    <label class="layui-form-label">模板名</label>
    <div class="layui-input-block">
      <input type="text" name="templateName" lay-verify="title" autocomplete="off" placeholder="模板名字" class="layui-input">
    </div>
    </div>
    
   <div class="layui-form-item">
    <label class="layui-form-label">类型：</label>
    <div class="layui-input-block">
      <input type="radio" name="templateType" value="1" title="代码" checked="">
      <input type="radio" name="templateType" value="2" title="协议">
    </div>
  </div>
    
    <div class="layui-form-item" style="margin-top:  20px;">
        <div class="layui-input-block">
            <button  id="submit" class="layui-btn"  lay-submit lay-filter="addVersion">新增模板</button>
        </div>
    </div>
  
</form>

<script>
    layui.use('form', function(){
        var form = layui.form;
        form.on('submit(addVersion)', function (data) {
        	var d = {}
            d.curNode = data.field.templateType;
            d.fileName = data.field.templateName;
            d.content = data.field.content;
            $.ajax({
                type: 'POST',
                url: '/zproto/module/saveTemplateDetail',
                dataType: 'json',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(d),
                success: function(data){
                	var code = data.code;
                    var str = data.tips;
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    //console.log(body.html()); //得到iframe页的body内容
                    layer.confirm(str, {
                        btn: ['ok'] //按钮
                    }, function () {
                    	parent.layer.close(index); //再执行关闭
                    	if(code == 0){
                             parent.window.location.reload();
                    	}
                    });
                },
                error: function(jqXHR){console.log(jqXHR)},
            });
            return false;
    });});
</script>

</body>
</html>
